package cn.liujianbo.easycode;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@MapperScan("cn.liujianbo.easycode.mapper")
@SpringBootApplication
@Slf4j
public class EasyCodeApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(EasyCodeApplication.class, args);

        Environment environment = context.getBean(Environment.class);
            String contextPath = environment.getProperty("server.servlet.context-path");
            if (StrUtil.isEmpty(contextPath)) {
                contextPath = "";
            }
            String port = environment.getProperty("server.port");

            try {
                String ip = InetAddress.getLocalHost().getHostAddress();
                log.info("\n项目访问地址：http://{}:{}{}", ip, port, contextPath);
                log.info("\n项目swagger地址：http://{}:{}{}{}", ip, port, contextPath, "/doc.html");
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
    }

}
